package com.hxm.drawview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by hxm on 2017/10/23.
 * 描述：
 */
public class PathView extends View {
    private Paint paint;
    private Path path;

    public PathView(Context context) {
        super(context);
        init();
    }

    public PathView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    //    @TargetApi(21)
    private void init() {
        paint = new Paint();
        path = new Path();
        paint.setColor(Color.RED);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);
        //画图形
//        path.addCircle(200,200,100, Path.Direction.CCW);
//        path.addCircle(300,200,100, Path.Direction.CW);
        //画线
//        path.lineTo(100,100);
//        path.moveTo(300,400);
//        path.rLineTo(200,0);
//        path.moveTo(100,100);
//        RectF rectF=new RectF(100,100,300,200);
//        path.arcTo(rectF,-90,120,false);
        //close,它的作用是把当前的子图形封闭，即由当前位置向当前子图形的起点绘制一条直线。
//        path.moveTo(300,300);
//        path.lineTo(500,600);
//        path.lineTo(300,800);
//        path.close();
        //心形
        RectF rectF = new RectF(200, 200, 400, 400);
        RectF rectF1 = new RectF(400, 200, 800, 400);
        path.addArc(rectF, -90, 90);
        path.arcTo(rectF1, -180, 225, false);
        path.lineTo(400, 542);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(path, paint);
    }
}
